package com.hdu.controller.classManagement;

import com.hdu.entity.Exam;
import com.hdu.pojo.*;
import com.hdu.service.IExamService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 成绩控制器
 *
 * @author xiaobai
 * @since 2024-05-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "成绩管理接口")
@RequestMapping("/exam")
public class ExamController {

    private final IExamService examService;

    @GetMapping
    public Result<List<Exam>> listExam(String grade, String label, String start,
                           String end, String examName) {
        log.info("考试列表查询, 参数: {},{},{},{},{}", grade, label, start, end, examName);
        List<Exam> examList = examService.listExam(grade, label, start, end, examName);
        return Result.success(examList);
    }

    @GetMapping("/wholeClass/{id}")
    public Result<List<String>> listClass(@PathVariable String id) {
        log.info("查询参考班级信息, id: {}", id);
        List<String> listClass = examService.listClass(id);
        return Result.success(listClass);
    }

    @GetMapping("/detail/{id}")
    public Result<Exam> listExam(@PathVariable String id) {
        log.info("查询考试详细信息, id: {}", id);
        Exam exam = examService.detailExam(id);
        return Result.success(exam);
    }

    @GetMapping("/wholeGrade")
    public Result<PageBean<Score>> page(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer limit,
                                        String id, String name, String prop, String order, String cID, String mID) {
        log.info("总体学生成绩查询, 参数: {},{},{},{},{},{},{},{}", page, limit, id, name, prop, order, cID, mID);
        //调用service分页查询
        PageBean<Score> pageBean = examService.page(page, limit, id, name, prop, order, cID, mID);
        return Result.success(pageBean);
    }

    @GetMapping("/subjectGrade")
    public Result<List<Rank>> page(String cID, String mID, String subject) {
        log.info("班级成绩查询, 参数: {},{},{}", cID, mID, subject);
        List<Rank> rankList = examService.classGrade("", cID, mID, subject);
        return Result.success(rankList);
    }

    @GetMapping("/requireFollow")
    public Result< List<List<Rank>>> requireFollow(String cID, String mID, String subject) {
        log.info("班级成绩情况查询, 参数: {},{},{}", cID, mID, subject);
        List<List<Rank>> rankList = examService.requireFollow( cID, mID, subject);
        return Result.success(rankList);
    }

    @GetMapping("/containGrade")
    public Result<List<Rank>> page(String sID, String cID, String mID, String[] subject) {
        log.info("成绩组成查询, 参数: {},{},{},{}", sID, cID, mID, subject);
        List<Rank> rankList = examService.containGrade(sID, cID, mID, subject);
        return Result.success(rankList);
    }

    @GetMapping("/classTable")
    public Result<List<Table>> classTable(String cID, String mID, String subject) {
        log.info("班级成绩分析表查询, 参数: {},{},{}", cID, mID, subject);
        List<Table> tableList = examService.classTable(cID, mID, subject);
        return Result.success(tableList);
    }

    @GetMapping("/subjectTable")
    public Result<List<Table>> subjectTable(String subject, String mID) {
        log.info("班级成绩分析表查询, 参数: {},{}", subject, mID);
        List<Table> tableList = examService.subjectTable(subject, mID);
        return Result.success(tableList);
    }

    @GetMapping("/averageGrade")
    public Result<List<String[]>> averageGrade(String cID, String mID) {
        log.info("考试成绩平均分查询, 参数: {},{}", cID, mID);
        List<String[]>  averageGrade = examService.averageGrade(cID, mID);
        return Result.success(averageGrade);
    }

    @GetMapping("/gradeScore")
    public Result<?> gradeScore(String mID, String subject) {
        log.info("年级最高分查询, 参数: {},{}", mID, subject);
        return Result.success(examService.gradeScore(mID, subject));
    }

    @GetMapping("/listHistogram")
    public Result<?> histogram(String subject, String cID, String mID) {
        log.info("班级成绩分段查询, 参数: {},{},{}", cID, mID, subject);
        return Result.success(examService.listHistogram(subject, cID, mID));
    }

    @GetMapping("/listLabel")
    public Result<List<Rank>> label(String cID, String mID, String subject, String score) {
        log.info("班级成绩分段学生查询, 参数: {},{},{},{}", cID, mID, subject, score);
        List<Rank> rankList = examService.listLabel(subject, cID, mID, score);
        return Result.success(rankList);
    }

}





